package com.example.conference.mapper;

import com.example.conference.domain.CourseStudent;
import com.example.conference.domain.CourseTeacher;
import com.example.conference.domain.User;
import com.example.conference.domain.dto.PageParam;
import com.example.conference.domain.vo.CourseTeacherForStudentVo;
import com.example.conference.domain.vo.CourseTeacherVo;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface CourseTeacherMapper {
    @Select("select * from course_teacher")
    List<CourseTeacherVo> queryAll();
//    @Select("<script>"+
//            "select * from course_teacher where dept_id in \n"+
//            "<foreach collection='Deptlist' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> \n" +
//            "</script>")
    //查询本专业，以及不限专业的课 开课情况
    @Select("select * from course_teacher where major_id in (1000,#{majorId})")
    @Results(id= "CourseTeacherForStudentMap",value= {
            @Result(column="user_id", property="teacher" ,
                    one=@One(select="com.example.conference.mapper.UserMapper.queryByIdToVo")),
            @Result(column="course_id", property="course" ,
                    one=@One(select="com.example.conference.mapper.CourseMapper.queryById")),
            @Result(column="courseNature_id", property="courseNature" ,
                    one=@One(select="com.example.conference.mapper.CourseNatureMapper.queryById")),
    })
    Page<CourseTeacherForStudentVo> queryByMajor(Integer userId, Integer majorId);

    @Select("select * from course_teacher where user_id = #{userId}")
    @Results(id= "CourseTeacherMap", value= {
            @Result(column="user_id", property="teacher" ,
                    one=@One(select="com.example.conference.mapper.UserMapper.queryByIdToVo")),
            @Result(column="course_id", property="course" ,
                    one=@One(select="com.example.conference.mapper.CourseMapper.queryById")),
            @Result(column="dept_id", property="dept" ,
                    one=@One(select="com.example.conference.mapper.DeptMapper.queryById")),
            @Result(column="courseNature_id", property="courseNature" ,
                    one=@One(select="com.example.conference.mapper.CourseNatureMapper.queryById")),
            @Result(column="major_id", property="major" ,
                    one=@One(select="com.example.conference.mapper.MajorMapper.queryById"))
    })
    Page<CourseTeacherVo> queryByTeacher(Integer userId);




    @Select("select * from course_teacher where ct_id = #{ctId}")
    @ResultMap("CourseTeacherMap")
    CourseTeacherVo queryByIdToMap(Integer ctId);

    @Select("select * from course_teacher where ct_id = #{ctId}")
    CourseTeacher queryById(Integer ctId);

    @Select("select * from course_teacher")
    @ResultMap("CourseTeacherMap")
    List<CourseTeacherVo> query();

    @Update("update course_teacher Set curNum = #{curNum} where ct_id = #{ctId}")
    Integer updateCurNum(Integer ctId, Integer curNum);

    @Insert("insert into course_teacher (course_id,user_id,dept_id, courseNature_id,major_id,term,maxNum) VALUES (#{courseId}, #{userId},#{deptId},#{courseNatureId}, #{majorId},#{term},#{maxNum})")
    Integer add(CourseTeacher courseTeacher);

    @Delete("delete from course_teacher where ct_id = #{ctId}")
    Integer delete(Integer ctId);
}
